package org.jypj.dev.service.impl;


import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;
import org.jypj.dev.model.WorkFile;
import org.jypj.dev.dao.IWorkFileDao;
import org.jypj.dev.service.IWorkFileService;
import org.jypj.dev.util.Page;

@Service("workFileService")
public class WorkFileServiceImpl implements IWorkFileService {
	
    @Resource 
    private IWorkFileDao workFileDao;
    
    /**
	 * 保存    
	 * 字段为空的不存防止覆盖存在默认值的字段
	 * @param workFile
	 * @return 保存后的对象包括ID
	 */	
	public int saveWorkFileByField(WorkFile workFile){
		String uuid =UUID.randomUUID().toString().replace("-", "").trim();
		workFile.setId(uuid);
		return workFileDao.saveWorkFileByField(workFile);
	}
	
	/**
	 * 保存    
	 * 所有字段全都保存
	 * @param workFile 
	 * @return 保存后的对象包括ID
	 */	
	public int saveWorkFile(WorkFile workFile){
		String uuid =UUID.randomUUID().toString().replace("-", "").trim();
		workFile.setId(uuid);
		return workFileDao.saveWorkFile(workFile);
	}
    
    /**
	 * 根据ID删除
	 * @param id 主键ID
	 * @return 删除记录数
	 */	
    public int deleteWorkFileById(String id){
    
    	return workFileDao.deleteWorkFileById(id);
    }
    
   	/**
	 * 根据对象删除
	 * @param id 主键ID
	 * @return 
	 */	
    public int deleteWorkFileByObject(WorkFile workFile){
    
    	return workFileDao.deleteWorkFileByObject(workFile);
    }
    /**
	 * 更新  
	 * 只更新值不为空的字段
	 * @param workFile 
	 * @return 保存后的对象包括ID
	 */	
    public int updateWorkFileByField(WorkFile workFile){
    
    	return workFileDao.updateWorkFileByField(workFile);
    }
    
    /**
	 * 更新  
	 * 更新所有字段
	 * @param workFile 
	 * @return 保存后的对象包括ID
	 */	
    public int updateWorkFile(WorkFile workFile){
    
    	return workFileDao.updateWorkFile(workFile);
    }
    
   /**
	 * 按ID查询
	 * @parm id 主键ID
	 * @return WorkFile 
	 */	
    public WorkFile selectWorkFileById(String id){
    
    	return workFileDao.selectWorkFileById(id);
    }
    
    /**
	 * 分页查询 包含条件
	 * @param page 分页对象
	 * @param map  查询条件  
	 * @return  List<WorkFile>
	 */	
     public Page selectOnePageByMap(Page page,Map<String,Object> map){
     	 List<WorkFile> workFiles =workFileDao.selectOnePageByMap(page,map);
	     	if(workFiles!=null&&workFiles.size()>0){
	     		page.setResult(workFiles);
	     	}else{
	     		page.setResult(new ArrayList<WorkFile>());
	     	}
	     	return page;
     }
    /**
	 * 分页查询 包含对象条件
	 * @param page 分页对象
	 * @param workFile  查询条件  
	 * @return Page
	 */	
     public Page selectOnePageByWorkFile(Page page,WorkFile workFile){
 		 List<WorkFile> workFiles =workFileDao.selectOnePageByWorkFile(page,workFile);
	     	if(workFiles!=null&&workFiles.size()>0){
	     		page.setResult(workFiles);
	     	}else{
	     		page.setResult(new ArrayList<WorkFile>());
	     	}
	     	return page;
     }
    
   /**
	 * 按条件查询全部的
	 * @param map  查询条件  
	 * @return  List<WorkFile>
	 */	
     public List<WorkFile> selectAllByMap(Map<String,Object> map){
     	return workFileDao.selectAllByMap(map);
     }
     
      
   /**
	 * 按条件查询全部的
	 * @param map  查询条件  
	 * @return  List<WorkFile>
	 */	
     public List<WorkFile> selectAllByWorkFile(WorkFile workFile){
     
    	 return workFileDao.selectAllByWorkFile(workFile);
     }
		
		/**
	 * 按条件查询单个对象
	 * @param map  查询条件  
	 * @return  WorkFile
	 */	
     public WorkFile selectObjectByMap(Map<String,Object> map){
     
    	 return workFileDao.selectObjectByMap(map);
     }
     
     /**
	 * 按条件查询单个对象
	 * @param map  查询条件  
	 * @return  WorkFile
	 */	
     public WorkFile selectObjectByWorkFile(WorkFile workFile){
     
     	return workFileDao.selectObjectByWorkFile(workFile);
     }
}